package com.zy.design.demo.creational;

/**
 * 抽象工厂模式
 * 特点：提供创建一系列相关对象的接口。
 */
interface MilkFactory {
    Milk createMilk();
}

class DairyFactory implements MilkFactory {
    public Milk createMilk() { return new CowMilk(); }
}

class SheepFactory implements MilkFactory {
    public Milk createMilk() { return new EwesMilk(); }
}

interface Milk { void drink(); }

class CowMilk implements Milk {
    public void drink() { System.out.println("喝牛奶"); }
}
class EwesMilk implements Milk {
    public void drink() { System.out.println("喝羊奶"); }
}

class Main {
    public static void main(String[] args) {
        MilkFactory factory = new DairyFactory();
        Milk cowMilk = factory.createMilk();
        cowMilk.drink();
        System.out.println("=========如果给个羊奶厂============");
        factory = new SheepFactory();
        Milk ewesMilk = factory.createMilk();
        ewesMilk.drink();
    }
}
